package com.nervenets.web.entity;

import com.google.gson.Gson;
import com.nervenets.utils.AESUtils;
import com.nervenets.utils.JodaUtils;

public class UserToken extends Model {
    private long userId;
    // 0-WX；1-APP；2-ADMIN；
    private int tokenType;
    private int time = JodaUtils.getTimestamp() + 0x93a80;

    public String getTokenStr() {
        try {
            return AESUtils.encryptData(new Gson().toJson(this));
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static void main(String[] args) throws Exception {
        UserToken token = new UserToken(1202, 0);
        System.err.println(token.getTokenStr());
    }

    public UserToken() {
    }

    /**
     * @param userId
     * @param tokenType 0微信，1App，2后台
     */
    public UserToken(long userId, int tokenType) {
        super();
        this.userId = userId;
        this.tokenType = tokenType;
        this.time = JodaUtils.getTimestamp() + 0x93a80;
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public int getTokenType() {
        return tokenType;
    }

    public void setTokenType(int tokenType) {
        this.tokenType = tokenType;
    }

    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }
}
